package A2016;

public class _7_剪邮票 {
	static boolean[] vis = new boolean[13];
	static int ans = 0;
	static int t = 0;

	public static void main(String[] args) {

		for (int i = 1; i <= 12; i++) {
			for (int j = i + 1; j <= 12; j++) {
				for (int k = j + 1; k <= 12; k++) {
					for (int x = k + 1; x <= 12; x++) {
						for (int y = x + 1; y <= 12; y++) {
							vis[i] = vis[j] = vis[k] = vis[x] = vis[y] = true;
							t = 0;
							dfs(i);
							if (t == 5) {
								ans++;
								System.out.println(i+" "+j+" "+k+" "+x+" "+y);
							}
								
							vis[i] = vis[j] = vis[k] = vis[x] = vis[y] = false;
						}
					}
				}
			}
		}
		System.out.println(ans);
	}

//	static char[] a = new char[] {'A','B','C','D','E','F','G','H','I','J','K','L'};
//	static HashSet<String> set = new HashSet<>();

	static void dfs(int x) {
		vis[x] = false;
		t++;
		if (x != 1 && x != 5 && x != 9 && vis[x - 1])
			dfs(x - 1);
		if (x != 4 && x != 8 && x != 12 && vis[x + 1])
			dfs(x + 1);
		if (x != 1 && x != 2 && x != 3 && x != 4 && vis[x - 4])
			dfs(x - 4);
		if (x != 9 && x != 10 && x != 11 && x != 12 && vis[x + 4])
			dfs(x + 4);
	}

	static void f(int k, int path[]) {// 全排列的另外一种方法，去重
		if (k == 12) {
			return;
		}
		for (int i = 0; i < 12; ++i) {
			// if (i > 0 && a[i] == a[i - 1] && !vis[i - 1])
			// continue;//现在准备选取的元素和上一个元素相同，但是上一个元素还没被使用

//	      if (!vis[i]) {//没有被用过的元素可以抓入到path
//	        vis[i] = true;//标记为已访问
//	        path[k] = a[i];//将a[i]填入到path[k]中
//	        f(k + 1, path);//递归
//	        vis[i] = false;//回溯
//	      }

		}
	}

}
